/*
 * Copyright the original author or authors.
 * 
 * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *	  http://www.mozilla.org/MPL/MPL-1.1.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.milib.display.ui.scroller {
	import com.googlecode.milib.base.IMLBroadcasterListener;

	import flash.display.MovieClip;
	import flash.utils.getQualifiedClassName;

	/**
	 * @author Marek Brun
	 */
	public class MCScroller extends MCScrollerWithConstantLengthSlider implements IMLBroadcasterListener {

		private var up:MovieClip;
		private var mid:MovieClip;
		private var dn:MovieClip;
		private var upLength:Number;
		private var dnLength:Number;
		private var midLength:Number;
		private var humps:MovieClip;

		public function MCScroller(mc:MovieClip) {
			super(mc);
			
			up=mlmc.getMC('btnSlider.up');			mid=mlmc.getMC('btnSlider.mid');			dn=mlmc.getMC('btnSlider.dn');			humps=mlmc.getMC('btnSlider.humps');
			
			upLength=mid.y;
			dnLength=sliderLength-dn.y;
			midLength=sliderLength-upLength-dnLength;
			
			if(getQualifiedClassName(this).split('::')[1]=='MCScroller'){
				setPosition(0, 1);
			}
		}
		
		override protected function draw():void {
			mc_btnSlider.visible=visibleToTotal<1;
			var sliderLength:Number=Math.max(visibleToTotal*lengtH, upLength+dnLength+8);
			mid.height=sliderLength-upLength-dnLength;
			dn.y=mid.y+mid.height;
			humps.y=mid.y+mid.height/2;
			mc_btnSlider.y=(lengtH-sliderLength)*position;
		}
		
		override protected function getSliderLength():Number {
			return dn.y+dn.height;
		}
		
	}
}
